#ifndef	STRUCTSFAT_H
#define	STRUCTSFAT_H
//#define MAX_CLUSTERS INT32_MAX
#include <stdint.h>

typedef int32_t CLUSTER;
typedef int32_t date_t;

typedef uint32_t BLOQUE; //1 Bloque = 2 sectores = 1024 bytes
static const int32_t SizeOfBloque = 1024;
static const int32_t sectoresPorBloque = 2;

typedef struct {
	int32_t bytes_per_sector;
	int32_t sectors_per_cluster;
	int32_t reserved_sectors;
	int32_t number_of_FATs;
	int32_t sectors; /*o long?*/
	int32_t Sectors_per_fileAllocationTable;
} __attribute__((packed)) BootSector;
	
typedef struct {
	int32_t sectors_per_FAT;
	int32_t root_dir_1st_cluster;
} __attribute__((packed)) FAT32Section;
	
typedef struct {
	char FileName[8 + 1];
	char fileExtension[3 + 1];
	char attr; /*0x0F determina un LFN*/
	char highBytesFirstCluster[2 + 1];
	char lowBytesFirstCluster[2 + 1];
	int32_t fileSize;
} __attribute__((packed)) DirectoryTable;

typedef struct {
	char fileName[13 + 1];
	CLUSTER firstCluster;
	int32_t size;
	unsigned char attribute;
	date_t createDate;
} __attribute__((packed)) FILE_INFO;

typedef struct Nodo_CLUSTER {
	CLUSTER cluster;
	struct Nodo_CLUSTER *nxt;
} __attribute__((packed)) Nodo_CLUSTER;

typedef struct Fifo_CLUSTER {
	Nodo_CLUSTER *Head;
	Nodo_CLUSTER *Tail;
} __attribute__((packed)) Fifo_CLUSTER;

typedef uint32_t SECTOR;

typedef struct Nodo_SECTOR {
	SECTOR sector;
	struct Nodo_SECTOR *nxt;
} __attribute__((packed)) Nodo_SECTOR;

typedef struct FIFO_SECTOR {
	Nodo_SECTOR *Head;
	Nodo_SECTOR *Tail;
} __attribute__((packed)) FIFO_SECTOR;

#define MAX_FILENAME_SO 13 + 1
//borrar la siguiente constante
#define TEST_DISK "/home/utn_so/fat32.disk"

static const int32_t _SubDirectory = 0x10;
static const int32_t _Archive = 0x20;

static const CLUSTER FreeCluster = 0;
static const CLUSTER EndCluster  = 0x0FFFFFFF;
static const CLUSTER BusyCluster = 0x0FFFFFFF;

#endif
